<?php
/**
 * Created by PhpStorm.
 * User: yuanjie
 * Date: 15/10/9
 * Time: 下午1:57
 */
class MaintenanceShops extends Eloquent
{
    protected $table = "maintenance_shops";

    /**
     * @Author:      kc
     * @DateTime:    2017-02-24 14:42:29
     * @Description: 门店列表
     * @Param: $city_id 城市id
     * @Return: Object
     */
    public static function getShop($city_id){
        return MaintenanceShops::where('city_id',$city_id)
            ->where('status',1)
            ->where('is_show',1)
            ->select([
                'id',
                'name',
                'address',
                'longitude',
                'latitude',
                'tel_phone',
                'small_image',
                'desc',
            ])
            ->get();
    }
    /**
     * @Author:      kc
     * @DateTime:    2017-02-27 10:25:20
     * @Description: 门店详情
     * @Param: $shop_id 门店id
     * @Return: Object
     */
    public static function getDetails($shop_id){
        return MaintenanceShops::where('id',$shop_id)
            ->where('status',1)
            ->where('is_show',1)
            ->select([
                'id',
                'name',
                'address',
                'longitude',
                'latitude',
                'tel_phone',
                'small_image',
                'image',
                'business_start_time',
                'business_end_time',
                'desc',
            ])
            ->first();
    }

    /**
     * @Author:      sqq
     * @DateTime:    2018-08-17 09:23:20
     * @Description: 根据城市id获取当前城市已开放的区县
     * @Param: $city_id String 城市id
     * @Return: Object
     */
    public static function getRegion($city_id){
        return MaintenanceShops::join('resource_region','maintenance_shops.region_id','=','resource_region.id')
            ->distinct()
            ->where('maintenance_shops.city_id',$city_id)
            ->where('maintenance_shops.status',1)
            ->where('maintenance_shops.is_show',1)
            ->orderBy('resource_region.id','asc')
            ->select([
                'resource_region.id',
                'resource_region.region_name',
            ])
            ->get();
    }

    /**
     * @Author:      sqq
     * @DateTime:    2018-08-17 09:43:29
     * @Description: 门店列表
     * @Param: $city_id 城市id
     * @Param: $region_id 区县id
     * @Return: Object
     */
    public static function getShopWechat3($city_id, $region_id){
        $shops = new MaintenanceShops();
        if($city_id){
            $shops = $shops->where('city_id',$city_id);
        }
        if($region_id){
            $shops = $shops->where('region_id',$region_id);
        }
        $shops = $shops->where('status',1)
            ->where('is_show',1)
            ->select([
                'id',
                'name',
                'address',
                'longitude',
                'latitude',
                'tel_phone',
                'small_image',
                'image',
                'business_start_time',
                'business_end_time',
                'desc',
            ])
            ->get();
        return $shops;
    }

	/**
     * @Author:      zk
     * @DateTime:    18-9-5 下午5:45
     * @Description: 获取指定状态的门店信息
     * @param array $status_arr 门店状态数组 默认为 [1]  1:正常;0:关闭;
     * @return array
     */
    public static function getAllShopInfo($status_arr = [1]) {
        $select_arr = [
            'id', 'name', 'desc', 'address', 'status', 'city_id',
        ];
        $result = MaintenanceShops::whereIn('status', $status_arr)
                ->select($select_arr)
                ->get()
                ->toArray();
        return $result;
    }


    /**
     * @Author:      sqq
     * @DateTime:    2018-10-24 下午14:49
     * @Description: 获取门店所在城市信息
     * @param 
     * @return []
     */
    public function cityinfo()
    {
        return $this->hasOne('ResourceCityType',"id","city_id");
    }

}
